<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="edu.fau.scanny.r.*"%>
<%@ page import="edu.fau.scanny.r.stromal.model.*"%>
<%@ page import="edu.fau.scanny.r.stromal.servlet.*"%>
<%@ page import="org.apache.commons.lang.StringUtils"%>
<%@ page import="edu.fau.scanny.stromal.*"%>
<%@ page import="java.text.DecimalFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Stromal Signal Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="css/table.css">
</head>
<body>
	<table class="center">
		<tr>
			<td><a href="process.jsp"
				title="Click to see process description."><img
					src="img/page3_banner_2.png" height="400" width="1000" /></a></td>
		</tr>
	</table>
	<h1 style="text-align: center">Stromal Signal Results</h1>
	<table class="center">
		<tr>
			<td colspan=4>This page allows you to validate your approach,
				especially your selection of a P<sub>Lymphoid</sub> value, by
				comparing the relative distributions of a manually curated list of
				stromal-specific genes (keratins, Foxn1, etc) versus a manually
				curated list of lymphoid-specific genes (Rag1, Cd4, etc). The
				(measured) distribution of both gene sets in RNA from whole tissue
				should be essentially random, while the (measured) distribution of
				lymphoid-specific genes should be higher than, and cluster
				distinctly from, that of stromal-specific genes, using RNA from
				purified lymphoid cells. This distribution should be inverted in
				(calculated) stromal signals, i.e., signals for genes in the
				stromal-specific list should be higher than that of genes from the
				lymphoid-specific list. Note that it is possible to force this to
				happen by selecting unnaturally large P<sub>Lymphoid</sub> values.
				However, in this case, the distribution of genes in the Affy Mask
				list (consisting of 100 ubiquitously expressed genes) should be
				skewed, and will visually differ from the distributions seen in
				whole tissue or purified lymphoid cells. While there are some cases
				where this may be desirable (e.g., when false positive results need
				to be minimized), in general, this would be an indication that you
				should adjust your P<sub>Lymphoid</sub> value to a lower level.
			</td>
		</tr>
	</table>
	
		<%
			Map<String, StromalOutput> stromalOutputs = (Map<String, StromalOutput>) request.getAttribute("stromalOutputs");
			DecimalFormat df = new DecimalFormat("###.##");
			for (String wholePartVar : stromalOutputs.keySet()) {
				StromalOutput so = stromalOutputs.get(wholePartVar);
		%>
		<table class="border">
		<tr>
			<td colspan=3 class="centerLeft" style="border-bottom: 1px solid #FFCA5E;"><strong><big> <%=wholePartVar%>
				</big></strong></td>
		</tr>
		<tr>
			<td style="border-right: 1px solid #DDDDDD;"><img src="<%=so.getBoxPlotFile().getName()%>"
				height="400" width="400" /></td>

			<td style="border-right: 1px solid #DDDDDD;"><img
				src="<%=so.getComparisonPlot().getName()%>" height="400" width="400" /></td>
			<td><img src="<%=so.getMskPlot().getName()%>"
				height="400" width="400" /></td>

		</tr>
		<tr>
			<td style="border-right: 1px solid #DDDDDD;"></td>
			<td style="border-right: 1px solid #DDDDDD;">Lymphoid-Specific Gene Depletion = <%=df.format(so.getLymphSpecificDepletion())%><br>Stromal-Specific
				Gene Enrichment = <%=df.format(so.getStromalSpecificEnrichment())%></td>
			<td>Calc.Stroma: Mask List Mean = <%=df.format(so.getStromalMskListMean())%>,
				StdDev = <%=df.format(so.getStromalMskListStandDev())%><br>
				Tissue: Mask List Mean = <%=df.format(so.getTissueMskListMean())%>,
				StdDev = <%=df.format(so.getTissueMskListStandDev())%></td>
		</tr>
		</table>
		<br>
		<%
			}
		%>
	
	<table class="centerCenter">
		<tr>
			<td class="centerCenter">
				<!--  <a href="savefile.php?file=">Normalized Whole Tissue Average Signal</a>-->
				<form method="get" action="download" name="downloadNorm">
					<input type="hidden" name="file"
						value="<%=((File) request.getAttribute("wholeTissue")).getAbsolutePath()%>" />
					<button value="submit" name="submit">
						<big>Normalized Whole Tissue Average Signal</big>
					</button>
				</form>
			</td>

			<td class="centerCenter">
				<form method="get" action="download" name="downloadNorm">
					<input type="hidden" name="file"
						value="<%=((File) request.getAttribute("lymphocyte")).getAbsolutePath()%>" />
					<button value="submit" name="submit">
						<big>Normalized Lymphocyte Average Signal</big>
					</button>
				</form>
			</td>

			<td class="centerCenter">
				<form method="get" action="download" name="downloadNorm">
					<input type="hidden" name="file"
						value="<%=((File) request.getAttribute("stromal")).getAbsolutePath()%>" />
					<button value="submit" name="submit">
						<big>Normalized Calculated Stromal Signal</big>
					</button>
				</form>
			</td>

			<td class="centerCenter">
				<form method="get" action="download" name="downloadNorm">
					<input type="hidden" name="file"
						value="<%=((File) request.getAttribute("all")).getAbsolutePath()%>" />
					<button value="submit" name="submit">
						<big>All Signals Combined</big>
					</button>
				</form>
			</td>
			<%
				String servletPath = StringUtils.replace(getServletContext().getRealPath("index.jsp"), "index.jsp", "");
			%>
			<td class="centerCenter">
				<form method="get" action="download" name="downloadNorm">
					<input type="hidden" name="file"
						value="<%=servletPath + "lists/lists.xlsx"%>" />
					<button value="submit" name="submit">
						<big>Probe Set Lists (Lymphoid, Stromal, Mask)</big>
					</button>
				</form>
			</td>
		</tr>
	</table>
	<!--  
	<table class="center">
		<tr>
			<td colspan=2>Selected P Lymphoid Values:</td>
		</tr>
		<%String[] prows = request.getAttribute("plymphStr").toString().split("/n");
			for (String row : prows) {%>
		<tr>
			<td></td>
			<td><%=row%></td>
		<tr>

			<%}%>
		
	</table>
	-->
	<table class="center">
		<tr>
			<td colspan=2>Parameters:</td>
		<tr>
			<td><%=request.getAttribute("normalization")%> normalization<br />
				<%=WebPageStringUtils.log2S(request.getAttribute("log2"))%> output
				signal</td>
		</tr>
	</table>
	<table class="border">
		<tr>
			<td class="border">Time Point</td>
			<%
				Map<String, Map<String, List<CelFile>>> groupFilesMap = (HashMap<String, Map<String, List<CelFile>>>) request.getAttribute("groupMap");
				Map<Integer, String> orderMap = MetaFileUtils.orderMap(this.getServletContext().getRealPath("Order.txt"));

				for (int kk = 1; kk <= orderMap.size(); kk++) {
					String order = orderMap.get(kk);
			%>
			<td class="border" style="text-align: center;"><%=order%></td>
			<%
				}
			%>
		</tr>
		<%
			for (String group : groupFilesMap.keySet()) {
				Map<String, List<CelFile>> typeMap = groupFilesMap.get(group);
		%>
		<tr>
			<td class="border"><%=group%></td>

			<%
				for (int kk = 1; kk <= orderMap.size(); kk++) {
						String order = orderMap.get(kk);
						List<CelFile> celFiles = typeMap.get(order);
			%>
			<td class="border" style="text-align: center;">
				<table style="text-align: center;">
					<%
						for (CelFile celFile : celFiles) {
					%>
					<tr style="text-align: center;">
						<td style="text-align: center;"><a
							title="Percent Present = <%=celFile.getpPresent() + "\n"%>Scaling Factor = <%=celFile.getScalingFactor()%>"><%=celFile.getShortName()%></a></td>
					</tr>

					<%
						}
					%>
				</table>
			</td>
			<%
				}
			%>
		</tr>
		<%
			}
		%>
	</table>
	<table class="center">
		<tr>
			<td><b>*Mouse over sample name to view QC values.</b></td>
		</tr>
	</table>
</body>
</html>